// <copyright file="ClientSide_AutoPostback.aspx.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System;
using System.Globalization;
using System.Text;
using System.Web.UI.WebControls;

namespace YUIAspNetDemo.Calendar
{
    public partial class Client : BaseDemoPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.autoPostbackCalendar.CheckChanged += new EventHandler(autoPostbackCalendar_CheckChanged);
            this.autoPbUP.CheckChanged += new EventHandler(autoPbUP_CheckChanged);

            if(!IsPostBack)
            {
                ShowDates(autoPbUP, Label1);
                ShowDates(autoPostbackCalendar, lblSelectedDates);
            }
        }

        void autoPbUP_CheckChanged(object sender, EventArgs e)
        {
            ShowDates(autoPbUP, Label1);
        }

        private void ShowDates(YUIAspNet.Calendar cal, Label lbl)
        {
            StringBuilder sb = new StringBuilder();

            foreach (DateTime date in cal.SelectedDates)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}", sb.Length > 0 ? "," : "", date.ToShortDateString());
            }

            lbl.Text = sb.ToString();
        }

        void autoPostbackCalendar_CheckChanged(object sender, EventArgs e)
        {
            ShowDates(autoPostbackCalendar, lblSelectedDates);
        }
    }
}
